package com.woniu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.dto.DischargeRecordQueryDTO;
import com.woniu.entity.InpatientDischargeRecord;
import com.woniu.entity.InpatientRecord;
import com.woniu.mapper.InpatientDischargeAppMapper;
import com.woniu.mapper.InpatientDischargeRecordMapper;
import com.woniu.service.IDischargeRecordService;
import com.woniu.utils.ResponseEnum;
import com.woniu.utils.ResponseUtil;
import com.woniu.vo.DischargeRecordVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class IDischargeRecordServiceImpl implements IDischargeRecordService {
    @Resource
    private InpatientDischargeRecordMapper mapper;
    @Override
    public ResponseUtil listDischargeRecords(DischargeRecordQueryDTO queryDTO) {
        PageHelper.startPage(queryDTO.getPageNum(), queryDTO.getPageSize());
        List<DischargeRecordVO> records = mapper.listDischargeRecords(queryDTO);
        PageInfo<DischargeRecordVO> pageInfo = new PageInfo<>(records);
        return pageInfo.getSize() > 0 ?
                ResponseUtil.get(ResponseEnum.OK,pageInfo)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil addRecord(InpatientDischargeRecord inpatientDischargeRecord) {
        //添加出院记录
        Integer result = mapper.insertSelective(inpatientDischargeRecord);
        //查找住院信息，修改住院信息中的出院时间和状态

        return result > 0 ?
                ResponseUtil.get(ResponseEnum.OK,inpatientDischargeRecord.getId())
                : ResponseUtil.get(ResponseEnum.FAIL);
    }
}
